package 剑指offer;

public class _58左旋转字符串 {
    public static String reverseLeftWords1(String s, int n) {
        if(s == null || n <= 0){
            return s;
        }
        int step = n % s.length();
        char[] list = s.toCharArray();
        Reverse(list, 0, step-1);
        Reverse(list, step, s.length()-1);
        Reverse(list, 0, s.length()-1);

        return new String(list);
    }

    private static void Reverse(char[] list, int start, int end) {
        while (start < end){
            char temp = list[start];
            list[start] = list[end];
            list[end] = temp;
            start++;
            end--;
        }
    }

    public static void main(String[] args) {
        String s = "lrloseumgh";
        System.out.println(reverseLeftWords1(s,6));
    }
}
